/*
Whack all the ghouls you can!
Controls: WASD to hit the red holes, IJKL to hit the blue holes

Thank you to @RuadhanKM for help with the music!

@title: Monster Mayhem
@description: Whack all the ghouls you can in 60 seconds as they pop up from their holes!
@author: Gus Ruben
@tags: ['retro', 'timed']
@addedOn: 2024-11-4
*/


const EMPTY = "_";
const GROUND1="1";
const GROUND2="2";
const GROUND3="3";
const GROUND4="4";
const GROUND5="5";
const GROUND6="6";
const GROUND7="7";
const GROUND8="8";
const GROUND9="9";
const GROUND10="0";
const HOLE_RED = "R";
const HOLE_BLUE = "B";
const ZOMBIE = "Z";

// Title music (w/o main melody and drums)
const MUSIC_TITLE = tune`
250: A4^250 + A3~5000 + C3~5000 + E3~5000 + A2^16000,
1000,
250: B4^250,
250: A4^250 + A3~5000 + C3~5000 + E3~5000,
750,
250: B4^250,
250: C5^250,
250: E5^250,
250: F5^250,
250: E5^250,
250: C5^250,
250: E5^250 + B3~5000 + D3~5000 + F3~5000 + B2^16000,
1000,
250: C5^250,
250: E5^250 + B3~5000 + D3~5000 + F3~5000,
750,
250: B4^250,
250: C5^250,
250: E5^250,
250: F5^250,
250: E5^250,
250: C5^250`
const MUSIC_GAMEPLAY = tune`
250: A4^250 + A3~5000 + C3~5000 + E3~5000 + A2^16000 + C6~500 + E2/100 + D2/100 + C2/100 + E5/30 + D5/30 + C5/30,
250: E5/30 + D5/30 + C5/30,
250: B5~500 + E2/100 + D2/100 + C2/100 + E5/30 + D5/30 + C5/30,
250: E5/30 + D5/30 + C5/30,
250: A5~500 + E4/50 + D4/50 + C4/50 + E5/30 + D5/30 + C5/30,
250: B4^250 + E5/30 + D5/30 + C5/30,
250: A4^250 + A3~5000 + C3~5000 + E3~5000 + F5~500 + E5/30 + D5/30 + C5/30,
250: E4/50 + D4/50 + C4/50 + E5/30 + D5/30 + C5/30,
250: C6~500 + E5/30 + D5/30 + C5/30,
250: E4/50 + D4/50 + C4/50 + E5/30 + D5/30 + C5/30,
250: B4^250 + B5~500 + E2/100 + D2/100 + C2/100 + E5/30 + D5/30 + C5/30,
250: C5^250 + E2/100 + D2/100 + C2/100 + E5/30 + D5/30 + C5/30,
250: E5^250 + A5~500 + E4/50 + D4/50 + C4/50 + E5/30 + D5/30 + C5/30,
250: F5^250 + E5/30 + D5/30 + C5/30,
250: E5^250 + F5~500 + E5/30 + D5/30 + C5/30,
250: C5^250 + E5/30 + D5/30 + C5/30,
250: E5^250 + B3~5000 + D3~5000 + F3~5000 + B2^16000 + D6~500 + E2/100 + D2/100 + C2/100 + E5/30 + D5/30 + C5/30,
250: E5/30 + D5/30 + C5/30,
250: C6~500 + E2/100 + D2/100 + C2/100 + E5/30 + D5/30 + C5/30,
250: E5/30 + D5/30 + C5/30,
250: B5~500 + E4/50 + D4/50 + C4/50 + E5/30 + D5/30 + C5/30,
250: C5^250 + E5/30 + D5/30 + C5/30,
250: E5^250 + B3~5000 + D3~5000 + F3~5000 + A5~500 + E5/30 + D5/30 + C5/30,
250: E4/50 + D4/50 + C4/50 + E5/30 + D5/30 + C5/30,
250: D6~500 + E5/30 + D5/30 + C5/30,
250: E4/50 + D4/50 + C4/50 + E5/30 + D5/30 + C5/30,
250: B4^250 + C6~500 + E2/100 + D2/100 + C2/100 + E5/30 + D5/30 + C5/30,
250: C5^250 + E2/100 + D2/100 + C2/100 + E5/30 + D5/30 + C5/30,
250: E5^250 + B5~500 + E4/50 + D4/50 + C4/50 + E5/30 + D5/30 + C5/30,
250: F5^250 + E5/30 + D5/30 + C5/30,
250: E5^250 + A5~500 + E5/30 + D5/30 + C5/30,
250: C5^250 + E5/30 + D5/30 + C5/30`

const GAME_OVER_MELODY1 = tune`
1034.4827586206898: F5-1034.4827586206898 + E5~1034.4827586206898 + D5^1034.4827586206898 + C5/1034.4827586206898,
1034.4827586206898: E5-1034.4827586206898 + D5~1034.4827586206898 + C5^1034.4827586206898 + B4/1034.4827586206898,
31034.482758620692`;
const GAME_OVER_MELODY2 = tune`
2000: C5~2000 + D5-2000 + B4^2000 + A4/2000,
62000`;

const BONK_MELODY_HIT = tune`
333.3333333333333: D5~333.3333333333333,
10333.333333333332`;
const BONK_MELODY_MISS = tune`
333.3333333333333: D4^333.3333333333333,
10333.333333333332`;

const EMPTY_BITMAP = bitmap`
................
................
................
................
................
................
................
................
................
................
................
................
................
................
................
................`

const GROUND10_FRAME_1 = bitmap`
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCC0C0CCCCCCCCCC
CCC000CCCCCCCCCC
CCC606CCCCCCCCCC
CCC0000CCCC6CCCC
CCCC0000C0CCFCCC
CCCC0000CC0CCCCC
CCCC000000CCCCCC
CCCC0000CCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC`;
const GROUND10_FRAME_2 = bitmap`
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCC0C0CCCCCCCCCC
CCC000CCCCCCCCCC
CCC000CCCCCCCCCC
CCC0000CCCC6CCCC
CCCC0000C0CCFCCC
CCCC0000CC0CCCCC
CCCC000000CCCCCC
CCCC0000CCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC`;
const GROUND10_FRAME_3 = bitmap`
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCC0C0CCCCCCCCCC
CCC000CCCCCCCCCC
CCC606CCCCCCCCCC
CCC0800CCCC6CCCC
CCCC0000C0CCFCCC
CCCC0000CC0CCCCC
CCCC000000CCCCCC
CCCC0000CCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC`;

const CORE_LEGEND = [
	[ EMPTY, EMPTY_BITMAP ],
	[ GROUND1, bitmap`
CCCCCCCCCCCCCCCC
CCCC6CCCCCCCCCCC
CCCCCFCCCCCCCCCC
CCCCCFCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CC6CCCCCCCCCCCCC
CCC6CC6CCCCCCCCC
CCC6CFCCCCCCCCCC
CCCFCFCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC` ],
	[ GROUND2, bitmap`
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCC6CC
CCCCCCCCCCCC6CCC
CCCCCCCCCCCCFCCC
CCCCCCCCCC6CFCCC
CCCCCCCCCCCFCCCC
C6CCCCCCCCCCCCCC
CCFCCCCCCCCCCCCC
CCFCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC` ],
	[ GROUND3, bitmap`
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCC6CCCC
CCCCCCCCCCCCFCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC` ],
	[ GROUND4, bitmap`
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCC6CCCCCCCCCC
CCCC6CCCCCCCCCCC
CCCC6CCCCCCCCCCC
CCCCFCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCC6CFCCCCC
CCCCCCC6CFCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC` ],
	[ GROUND5, bitmap`
CCCCCCCCCCCCCCCC
CCCC6CCCCCCCCCCC
CCCCCFCCCCCCCCCC
CCCCCFCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCC11CCCC
CCCCCCCCC111CCCC
CCCCCCCCCCCCCCCC
CC6CCCCCCCCCCCCC
CCC6CC6CCCCCCCCC
CCC6CFCCCCCCCCCC
CCCFCFCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC` ],
	[ GROUND6, bitmap`
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCLLCCCCCCCCCC
CCC9LCCCCCCCCCCC
CC9999CCCCCCC6CC
CC9999CCCCCC6CCC
CCC999CCCCCCFCCC
CCCCCCCCCC6CFCCC
CCCCCCCCCCCFCCCC
C6CCCCCCCCCCCCCC
CCFCCCCCCCCCCCCC
CCFCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC` ],
	[ GROUND7, bitmap`
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCLCCCCCCCCCCC
CCCLCCCCCCC6CCCC
CC9999CCCCCCFCCC
C969969CCCCCCCCC
C999999CCCCCCCCC
C996699CCCCCCCCC
CC9999CCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC` ],
	[ GROUND8, bitmap`
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCC6CCCCCCCCCC
CCCC6CCCCCCCCCCC
CCCC6CCCCC11CCCC
CCCCFCCCCC1LLCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCC6CFCCCCC
CCCCCCC6CFCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC` ],
	[ GROUND9, bitmap`
CCCCCCCCCCCCCCCC
CCCC6CCCCCCCCCCC
CCCCCFCCCCCCCCCC
CCCCCFCCCCCCCCCC
CCCCCCCCCCCCCC8C
CCCCCCCCCCC88C8C
CCCCCCCCCC8CC8CC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC
CC6CCCCCCCCCCCCC
CCC6CC6CCCCCCCCC
CCC6CFCCCCCCCCCC
CCCFCFCCCCCCCCCC
CCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC` ],
  	[ GROUND10, GROUND10_FRAME_1 ],
	[ HOLE_RED, bitmap`
CCCCCCCCCCCCCCCC
C33333333333333C
C3CCCCCCCCCCCC3C
CCCCLLLLLLLLCCCC
CCLL00000000LLCC
CL000000000000LC
C00000000000000C
C00000000000000C
C00000000000000C
C00000000000000C
C00000000000000C
CC000000000000CC
CCCC00000000CCCC
C3CCCCCCCCCCCC3C
C33333333333333C
CCCCCCCCCCCCCCCC` ],
	[ HOLE_BLUE, bitmap`
CCCCCCCCCCCCCCCC
C77777777777777C
C7CCCCCCCCCCCC7C
CCCCLLLLLLLLCCCC
CCLL00000000LLCC
CL000000000000LC
C00000000000000C
C00000000000000C
C00000000000000C
C00000000000000C
C00000000000000C
CC000000000000CC
CCCC00000000CCCC
C7CCCCCCCCCCCC7C
C77777777777777C
CCCCCCCCCCCCCCCC` ],
];

const OVERLAYS = [
	bitmap`
................
................
................
................
..........FFFFFF
.........FFFFFFF
.........FFFFFFF
.........FFFFFFF
.........FFFFFFF
.........FFFFFFF
.........6FFFFFF
..........666666
................
................
................
................`,
	bitmap`
................
................
................
................
FFFFF...........
FFFFFF..........
FFFFFF..........
FFFFFF..........
FFFFFF..........
FFFFFF..........
FFFFF6..........
66666...........
................
................
................
................`,
	bitmap`
................
................
................
................
................
......FFFFFFFFFF
.....FFFFFFFFFFF
.....FFFFFFFFFFF
.....FFFFFFFFFFF
.....FFFFFFFFFFF
.....FFFFFFFFFFF
.....6FFFFFFFFFF
......6666666666
................
................
................`,
	bitmap`
................
................
................
................
................
FFFFFFFFFFFFFF..
FFFFFFFFFFFFFFF.
FFFFFFFFFFFFFFF.
FFFFFFFFFFFFFFF.
FFFFFFFFFFFFFFF.
FFFFFFFFFFFFFFF.
FFFFFFFFFFFFFF6.
66666666666666..
................
................
................`,
  	bitmap`
................
................
................
................
................
FFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFF
6666666666666666
................
................
................`,
]

const HAMMER = bitmap`
........3233....
.......323333...
........33333...
.........331....
............1...
................
................
................
................
................
................
................
................
................
................
................`;
const HAMMER_DOWN = bitmap`
........333.....
.......32333....
......323333....
.......3331.....
........33.1....
................
................
................
................
................
................
................
................
................
................
................`;

const MONSTERS = [
	[ bitmap`
................
................
................
................
................
................
................
................
................
................
.....88.........
....888DDD......
....DDDDDDDD....
................
................
................`, bitmap`
................
................
................
................
................
................
.....88DDDD.....
....882D202D....
....D20DDDDD....
....DDD00LD4....
.....DDD4444....
....77DDD447D...
....7D777777....
................
................
................`, bitmap`
......8DDD......
.....88D22D.....
.....88D022.....
.....02DDDDD....
.....2200DD4....
....DDD0LD44....
.....DDD4444....
...D777DDD47D...
..DD7D777D77D...
..DD.DD7777D1...
..D4.DD77D7D....
..1..7555575....
....5DD55555....
................
................
................`, bitmap`
................
.....88DDDD.....
....888D022.....
....822D222D....
....D02D00DD....
....DDD00LD4....
.....DDD4444....
..DD7777DD47D...
.D447D777777DD..
.D4..DD77DD.D1..
.14..D477D7.1...
.....7777D75....
....5DD55555....
................
................
................`,  bitmap`
........3233....
.......323333...
.....0DD33333...
....880D0311....
....80DDDDD1....
....DDD00DD4....
.....DD00444....
...D7777DD47D...
..DD7D777777D...
.1D4.DD77DDD1...
..1..D477D71....
.....7777D75....
....5DD55555....
................
................
................`, bitmap`
........333.....
.......32333....
.....0323333....
....8803331.....
....80DD33D1....
....DDD00DD4....
.....DD00444....
...D7777DD47D...
..DD7D777777D...
.1D4.DD77DDD1...
..1..D477D71....
.....7777D75....
....5DD55555....
................
................
................` ,  bitmap`
........3233....
.......323333...
........33333...
.........311....
.....8DDD0D1....
....880D0DD.....
....D0DDD0DD....
...DDDD00D44....
..DD7D00L477....
..D44777777DD...
..D1.D477D7DD...
..1..7777D711...
....5DDDD551....
................
................
................`, bitmap`
........3233....
.......323333...
........33333...
.........331....
............1...
................
................
................
................
................
.....88.........
....888DDD......
....DDDDDDDD....
................
................
................`],
  [ bitmap`
................
................
................
................
................
................
................
................
................
................
.....11101......
....10111111....
....11111111....
................
................
................`, bitmap`
................
................
................
................
................
......2222......
.....2202222....
....222220022...
....222222222...
....222202222...
...2222202222...
..22222222222...
....22222222....
................
................
................`, bitmap`
.......222......
......2222......
......22222.....
.....222202.....
.....220222.....
.....2222222....
.....2220222....
....222202222...
....222222222...
...222222222....
...222222222....
...222222222....
....2222222.....
................
................
................`, bitmap`
................
.......222......
.....222222.....
.....222202.....
.....2022222....
....222222222...
....222202222...
....222202222...
...2222222222...
..2222222222....
..2222222222....
..2222222222....
....2222222.....
................
................
................`,  bitmap`
........3233....
.......323333...
...2222233333...
..2222222311....
..2202220221....
...220222022....
...202202222....
...2222022222...
..22222222222...
..22222222222...
...2222222222...
...2222222222...
....22222222....
................
................
................`, bitmap`
........333.....
.......32333....
...222323333....
..222223331.....
..2202223321....
...220222022....
...202202222....
...2222022222...
..22222222222...
..22222222222...
...2222222222...
...2222222222...
....22222222....
................
................
................`,  bitmap`
........3233....
.......323333...
........33333...
.........311....
.......22..1....
....222202......
...20220222.....
..2220220222....
..2202222222....
..22222022222...
..22222022222...
...2222222222...
....22222222....
................
................
................`, bitmap`
........3233....
.......323333...
........33333...
.........331....
............1...
................
................
................
................
................
................
.....11111......
....11111111....
................
................
................`
  ],
  [ bitmap`
................
................
................
................
................
................
................
................
................
................
....HHH.........
.....HHHH.......
.....HHHHH......
................
................
................`, bitmap`
................
................
................
....HHH.........
.....HHHH.......
.....LLHHH......
....HHH6LLL.....
...HHHHHHHH.....
...H9999944H....
...990444444....
...99DD44044....
....HDD0DDHH....
...HHHHHHHH4H...
................
................
................`, bitmap`
.....HH.........
......HHH.......
......L6LL......
.....L99HH......
.....99944H.....
....9994444.....
...99044404.....
...9D444444.....
....DDD0444.....
....HDD0DDH.....
....HHHHHH4.....
....4HHHHHHH....
....HHHHHHHH....
................
................
................`, bitmap`
....HHH.........
.....HHHH.......
.....HHHHH......
.....LL6LLL.....
....HHHHHHH.....
...HH999HHHH....
...H9999944.....
...990444044....
...9DDD44444....
....HDD0DDHH....
...HHHHHHHH4H...
...H4HHHHHHLH...
....HHHHHHH6....
................
................
................`,  bitmap`
........3233....
....HHH323333...
.....HHH33333...
.....HH6L311....
....LLLHHHH1....
...HH999HHH.....
...H9944044.....
...990404444....
..990DD40444....
..9.DD0DDDHH....
...HHD0DDHHHH...
...HHHHHHHH4H...
....4HHHHH6L....
................
................
................`, bitmap`
........333.....
....HHH32333....
.....H323333....
.....HH3331.....
....LLLH33H1....
...HH999HHH.....
...H9944044.....
...990404444....
..990DD40444....
..9.DD0DDDHH....
...HHD0DDHHHH...
...HHHHHHHH4H...
....4HHHHH6L....
................
................
................`,  bitmap`
........3233....
.......323333...
........33333...
....HHHH.311....
...H.HHLL..1....
....LL6HHH......
...HH999HHH.....
..HH9944044.....
...99040444.....
...90DD4044.....
...9DD0DDDH.....
...HHD0DDHHH....
...HHHHHHHH4H...
................
................
................`, bitmap`
........333.....
.......32333....
......323333....
.......3331.....
........33.1....
................
................
................
................
................
....HHH.........
......HHH.......
.....HHHHH......
................
................
................`
  ],
  [ bitmap`
................
................
................
................
................
................
................
................
................
................
.....11111......
....11100600....
....06011111....
................
................
................`, bitmap`
................
................
................
................
........222.....
......220006....
...060002111....
...211111222....
...120F06062....
....110F062.....
...2211111111...
..211222221221..
..1F2LLL112112F.
................
................
................`, bitmap`
................
......2222......
.....110006.....
....0601112.....
....2222261.....
....11F0602.....
....2206061.....
....1122222.....
....L1111111....
...21LLL22121...
..F1L122LLL11F..
...FLLLL112LF...
....L111LL1.....
................
................
................`, bitmap`
................
................
.....222222.....
....22220602....
...200602111....
...211111022....
...12F060622....
....11F0622.....
...2211111111...
..211222221221..
..1F2LLL112112F.
..F.L221LLLL.F..
....LLLL111.....
................
................
................`,  bitmap`
........3233....
.......323333...
.....22233333...
...222220311....
..2200002111....
..0011111222....
...12F060222....
....11F0602.....
...221111122....
..211222221121..
.1112LLL11221F..
.FF.L221LLLLF...
....LLLL111.....
................
................
................`, bitmap`
........333.....
.......32333....
.....2323333....
...22223331.....
..2200003311....
..0011111222....
...12F060222....
....11F0602.....
...221111122....
..211222221121..
.1112LLL11221F..
.FF.L221LLLLF...
....LLLL111.....
................
................
................`,  bitmap`
........3233....
.......323333...
........33333...
.........311....
.....22222.1....
...22222600.....
..2200002111....
..0611111222....
...122602112....
....1F06022.....
...221106122....
..21122222112...
....2LLL1122....
................
................
................`, bitmap`
........3233....
.......323333...
........33333...
.........331....
............1...
................
................
................
................
................
................
......1112......
....22206112....
................
................
................`
  ],
  [ bitmap`
................
................
................
................
................
................
................
................
................
................
................
....30000003....
....33000033....
................
................
................`, bitmap`
................
................
................
................
................
....3......3....
....333..333....
................
................
................
....3.....33....
....33.3.333....
.....333333.....
......3.3.3.....
................
................`, bitmap`
.....00000......
....00000000....
...0300000030...
...0330000330...
...0030000300...
...0000000000...
...0000000000...
...0300000030...
...0330000330...
...0333303330...
...0033333300...
...0033330300...
....03030030....
................
................
................`, bitmap`
.......000......
.....000000.....
....00000000....
...0000000000...
...0300000030...
...0330000330...
...0000000000...
...0300000030...
...0330303330...
...033333333....
.....3.3333.....
.......3.3......
................
................
................
................`,  bitmap`
........3233....
.......323333...
.....0LL33333...
....000LL311....
...00000LLL1L...
...0000000LLL...
...0330003300...
...0000000000...
...0000000000...
...0030303300...
...033333333....
.....3.3333.....
.......3.3......
................
................
................`, bitmap`
........333.....
.......32333....
.....L323333....
....0LL3331L....
...000LL33L1L...
...0000LLLLLL...
...0330003300...
...0000000000...
...0000000000...
...0030303300...
...033333333....
.....3.3333.....
.......3.3......
................
................
................`,  bitmap`
........3233....
.......323333...
........33333...
.........311....
.....LLLLL.1....
....00LLLLL.....
...000LLLLLLL...
...00000LLLLL...
...0000000000...
...0330003300...
...0000000000...
...0030303300...
....33333333....
................
................
................`, bitmap`
........333.....
.......32333....
......323333....
.......3331.....
........33.1....
................
................
................
................
................
................
......0000......
....00300300....
................
................
................`
  ],
];

const GAME_OVER_ART = bitmap`
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000010000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000121000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000
00112221100000000000LLLLLLL0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000
00001210000000000LLL00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000
000001000000000LL000000000000000LL000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000
00000100000000L0000001111110000000L00000100000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000L000011100000011100000LL000000000000000000000000000000000000000000012100000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000110002222220001100000L00000000000100000000000000000000000000001122211000000000000000000000000000000000000001000000000000000000000010000000000000
0000000000000000002222222222220010000000000000000100000000000000000000000000000012100000000000000000000000000000000000000012100000000000000000000111000000000000
0000000000000000022222222222222001100000000000001210000000000000000000000000000001000000000000000000000000100000000000000001000000000000000000000010000000000000
0000000000000002222221122221222220000000000000112221100000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000022122211112222222222000000000000001210000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000
0000000000000222222211LL2222222222200000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000022222222LL22222211222200100000000000100000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000
000000000000222222222222222221L222220100000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000L001022222222222222222222222211000001110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000L001022222222222222222222222111000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000L0001022222111122222122222222111000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000
00000L0010222221111112222222222222111101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000
00000L0010222211111111222222222222111101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000
00000L0010212111111111122221222221111100066666600666666000000000000000000000006666660000000000000666666000000666666666666000000000000000020000000000000000000000
00000L0010222111111111L22211222221111L66666666666666666600000000006666000000066666666600000000006666666660006666666666666666000000000000121000000000000000000000
00000L001022211111111LL22222222221116666666999966666966610000000066666600000666699966660000000066669966666666666999999966666600000000000121000000000000000000000
00000L00102221111111LLL22222222211166666669999999669966600000000666966600000669999999660000000666699999966699999999999999999660000000011222110000000000000000000
00000L000102221111LLLL222222222111666669999996669999966600000000669996600000666699999660000000666999996666666999999966669999966000011222222222110000000000000000
000000000002222LLLLLL2221121221116666699996666666999966600000006669996600000066699996666000006666999966666666999996666669999966000000011222110000000000000000000
0000000000022222LLLL22221122211116666999666600666699966600000006699999660000006699999666000006669999966666666999966666666699966000000000121000000000000000000000
0000000000102222222222222222111166669996660000066669966600000066699999660000006699699966600006669999966600066999966666666666966000000000121000000000000000000000
0000000000100222122222222211111166699966600000006669966600000066699699666000006699699966600066669699960000006999966669966066666000000000020000000000000000000000
0000000000000221122222221111111L66699966000000000666966600000666999699966000000669699966660066699699960000006999966666966006660000000000010000000000000000000000
000000000000002221111111111111LL66699660000000000666666600000666999699966600000669669996660666696699960000006999966669966000000000000000010000000000000100000000
0000000000000001111111111111LLLL66699660L00000000066666000006669996669996600000669669996666666996699966000006999999999966000000000000000000000000000000100000000
00000000000000000111111111LLLLL06699966L000000000000000000006669996669996660000669966999666666996699966000006699999999966600000000000000000000000000001210000000
00000000000000000011111LLLLLLL0066999660000000010000000000066699666699999966000669966999966669966699966000006699999699966600000000000000000000000000112221100000
0000000000000000000001LLLLL0001166999660000006666666666660066699999999999966000669966699966669966699996000006699966669966600000000000000000000000000001210000000
0000000000000000000010000001110066999966000066666666666666666699999999999966000669966699996669966699996000006999966669966600000000000000000000000000000100000000
000000000000LL00000001111110000066999966600066999999999966666999666996999996600669966669996699666699996000006999966669966000666000000000000000000000000100000000
00000000000000L0000000000000000066699666600066699999999666666996666666999996600669966669996699666699996L00006999966666666006666600000000000000000000000000000000
000000000000000LL000000000000000L6699996660006669999966666669996666666999999666669966669999996666699996LLL006999966606666066696600000000000000000000000000000000
10000000000000000LLL000000000000066699966666669999999666666699666610066999996666699666669999966666699966LLL66999966600000666996600000000000000000000000000000000
00000000000000000000LLL0000000000666699966666699999966666669996660106669999996666996666699996666669999666L666999966660066669996600010000000000000000000000000000
0000000000000000000000000000000000666699996699999996666666699666612666699999966669966666699666666699996666666999996666666999996600121000000000000000000000000000
0000000000000000000000000000000000666669999999999966666669999966622666999999996699966606699666666999996666666999999666699999666600010000000000000000000000000000
00000000000000000000000000000000000666666999996666666666999999966126699999999999999996L6696666699999999966699999999999999999966000000000000000000000000000000000
000000000000000000000000000010000000066666696666666666666999996660166666999966999966666L666666666699996666666666999999996666660000000000000000000000000000000000
00000000000000000000000000012100000000666666666666666066666666660010666666666666666666LLL6660066666666666LLLL666666666666660000000000000000000000000000000000000
0000000000000000LLLLLLLLLLLL1LLL0000000000666666000000006666666000000666666666666666LLLL666666666666600LLL66666LLL0000000000000000000000000000000000000000000000
000000000000LLLLLLLLLLLLLLLLLLLLLLLL0000000006666666660000066666666666600006666666666666666666666666666666666666666660000000000000000000000000000000000000000000
0100000000LLLLLLLLLLLLLLLLLLLLLLLLLLLLL0000666666666666000666669999666660066666996666666999999666666666666669666666666000000000000000000000000000000000000000000
00000000LLLLLLLLLLLLL1LLLLLLLLLLLLLLLLLLL06666999999666666669999999999660666999999969999999999999999966999999999999966660000000000000000000000000000000000000000
000000LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL666699996699999666666696999996660666699996666999999999996699966669999999999999666000000000000000000000000000000000000000
0000LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL6669999666666669966666666999966600666669966666699999666666666996669999966666699966600000000000000000000000000000000000000
00LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL666999666666666699966606666999660000666699666L6699999666666666996669999666666669996600000000000000000000000000000000000000
0LLLLLLLLLL000000000LLLLLLLLLLLLLLLLL666999966LL00000669996660666999666000066699666L669999660666666669666999966LL66699996600000000000000000000001000000000000000
LLLLLLL000000000000000000LLLLLLLLLLL666999966LLLL0000069999660666699666000666996666L66999966666966L666666999966LLL66699966LL000000000000000000000000000000000000
LLLLL0000000000000000000000LLLLLLLLL66669996LLLLLLL00066999660066669966000666996666L669999666669666L66606999966LLL66699966LLLLL00000000000000000000000000000LLLL
LL000000000000000000000000000LLLLLLL66999966LLLLLLLL0006999666066669966606669966666L669999699999666LL00066999666L66699966LLLLLLLLLL000000000000000010LLLLLLLLLLL
L000000000000000000000000000000LLLLL6699996LLLLLLLLLL00669996600666999660666996666LL666999999999666LL00066999666666699966LLLLLLLLLLLLLLLLLLLLLLLLLL1LLLLLLLLLLLL
00000000000000000000000000000000LLLL6999966LLLLLLLLLLLL669996600666999666666966666LL666999999999666LL0006699966666999666LLLLLLLLLLLLLLLLLLLLLLLLLL111LLLLLLLLLLL
0000000000000000000000000000000000LL6999966LLLLLLLLLLLL66999660006669966666996666LLL666999996999666LL0006699999999996666LLLLLLLLLLLLLLLLLLLLLLLL1111111LLLLLLLLL
00000000000000000000000000000000000L6999966LLLLLLLLLLLL669996600066699966699666600LL66999999669966LLL0006699966669999666LLLLLLLLLLLLLLLLLLLLLLLLLL111LLLLLLLLLLL
0000000000000000000000000000000000006699966LLLLLLLLLLL66699966000066699666966666000L66999966666966LL00006999966666999666LLLLLLLLLLLLLLLLLLLLLLLLLLL1LLLLLLLLLLLL
00000000000000000000000000000000000066999966LLLLLLLLLL66699966L00066999969966666000066999966666966L006666999966L666999666LLLLLLLLLLLLLLLLLLLLLLLLLL1LLLLLLLLLL00
000000LLLLLLLLLLL000000000000010000006699996LLLLLLLLL666999666LLL0666999699666600000669999666666660066666999966LL669996666LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL000000
0LLLLLLLLLLLLLLLLLLLL0000000000000000669999966LLLLLL6669999966LLLL66699999666660000066999966L666600066966999966LL666999666LLLLLLLLLLLLLLLLLLLL000000000000000000
LLLLLLLLLLLLLLLLLLL1LLLL000000000000066999996666LL66666999966LLLLLL669999966666000006669996660000006699669999666LL6699966600000000000000000000000000000000000000
LLLLLLLLLLLLLLLLLL111LLLLLL000000000006699999666666666999966LLLLLLL6699996666600000066699966666666666996699999666LL66999966LLL0000000000000100000000000000000000
LLLLLLLLLLLLLLLLLLL1LLLLLLLL0000000000666999996666666999966LLLLLLLL66999966666LLL0066669999666666666996666999996666669999666LLLLLLL00000000000000000000000000000
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL0000000006666999999999996666LLLLLLLLL6669996666LLLLL6666999999666666999966699999996666699999666LLLLLLLLL00000000000000000000000000
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL00000000666669999999666666LLLLLLLLLL66696666LLLLLL6699999999999999999669999999999966669999966LLLLLLLLLLLLLLLL0000000000000000000
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL00000000666669996666666LLLLLLLLLLL6666666LLLLLLL6666669999999666666666669996666666666996666LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
0000LLLLLLLLLLLLL1LLLLLLLLLLLLLLLLL000000006666666666666LLLLLLLLLLLLL666666LLL1LLLL6666666666666666LLL6666666666LLL666666666LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
00000000LLLLLLLLL1LLLLLLLLLLLLLLLLLL000000000006666660LLLLLLLLLLLLLLLL6666LLL111LLLLLL66666666666LLLLLLLL66666LLLLLLLL6666LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
00000000000LLLLL111LLLLLLLLLLLLLLLLLLL000000000000000000LLLLLLLLLLLLLLLLLLLLLL1LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL0000000LLLLLLLLLLLLLLLL1LLLLLLLLLLLLLLLLLLLL
0000000000000L1111111LLLLLLLLLLLLLLLLLL0000000000000000000LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL000000000000000000000000000LLLLLL1LLLLLLL1LLLLLLLLDLLL
000000000000000L111LLLLLLLLLLLLLLLLLLLLL000000000000000000000LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL0000000000DD000000000000000000000000111LLLLLL11LLLLLLDDDLL
000000000000000001LLLLLLLLLLLLLLLLLLL1LLLL000000000000000000000000LLLLLLLLLLLLLLLLLLLLLLLLLLLLLL0000000000000000DDD000000000000000000000000L000000010LLLLLLDDLLL
0000000000000000010LLLLLLLLLLLLLLLLLLLLLLLL00000000000000000000000000000000LLLLLLLLL00000000000000000000000000000DD0000000000000000000000001D000000L0000001DDLLL
000000000000000000000LLLLLLLLLLLLLLLLLLLLLLLL000000000000000000000000000000000000000000000000000000000000000000000DD011111100000000000000001DD000001000001D100LL
00000000000000000000000LLLLLLLLLLLLLLLLLLLLLLL00000000000000000000000000000000000000000000000000000000000000000000D111111L111000000000001111111DD10010000DL00000
0000000000000000000000000LLLLLLLLLLLLLLLLLLLLLL000000000000000000000000000000000000000000000000000000000000000000D11111111LL11000000000000LLLDDLLL1D1D000DD0000L
000000000000000000000000000LLLLLCCLLLLLLLLLLLLLLL000000000000000000000000000000000000000000000000000000000000000D111LLL11111L110000000000001100000L11111D1DD0001
000000000000000000DD000DD0000LLCCLLLLLLLLLLLLLLLLL00000000000000000000000000000000000000000000000000000000000000D11L111L1111111100000000000L100000DLLLLDLLD1DDDD
000000000000000000DDD0D00DDDD0CCCLLLLLLLLLLLLLLLLLLL00000000000000000100000000000000000000000000000000000000000011L111111111111110000000000110000DD010D0001DLLLL
0000000000000000000DDD00DD000DCC0LLLLLLLLLLLLLLLLLLLLL000000000000000000000000000000000000000000000000000000000011L11L11111L1111100000000001L0000DD01000001000D1
0000000000000000000D000099999CCC000LLLLLLLLLLLLLLLLL1LL00000000000000000000000000000000000000000000000000000000111L111L111L1LL111L0001000001000000D0L0000010000D
000000000000000000D009999999999C000000LLLLLLLLLLLLLL1LLLL000000000000000000000000000000000000000000000000000000111L11L111L1111L1LL00000000010000000L10000010000D
00000000000000000D009966999999999990000LLLLLLLLLLLL111LLLLLL0000000000000000000000000000000000000000000000000011111LL111L1L11L11LLLLLLLLLLL11000000110000D10000D
00000000000000000D099666699999999999900000LLLLLLL1111111LLLLLLL000000000000000000000000000000000000000000000001111111111L11LL111LLLLLLLLLLL11LLLLLL1100001D00001
0000000000000000D0D9996669999999999999900000LLLLLLL111LLLLLLLLLLLL0000000000000000000000000000000000LLLLLLLLLD111111111L111L111LLLLLLLLLLLLL1LLLLLL11LLLL1000011
000000000000000DD0099966669999999666999C00000000LLLL1LLLLLLLLLLLLLLLLLL00000000000000000000000000LLLLLLLLLLLLD11L1111111111L111LLLLLLLLLLLL111LLLLL1LLLLL1LLLL11
00000000000000000099999FF69999966666999C0000000000001LLLLLLLLLLLLLLLLLLLLLLLL000000000000000000000000000LDDL1D111LL11111111L111LLLLLLLLLLLL11LLLLLL1LLLLD1LLLL11
DD00000000000000009999999F99996666F9999C880000000000000000000LLLLLLLLLLLLLL00LLL00000000000000000000000000DDD111111LLLL1111111LLLLLLLLLLLLL11LLLLLL1LLLLD1LLLL11
44D000000000000000999999999996666F9999980080000000000000000000000000000000000000000000000000000000000000000D111L1111111LLL1111LL0000000000011LLLLLL1LLLLD1LLLL11
444DD000DDD0000000999669999999FFF999999C008080000000000000000000000000000000000000000000000000000000000000D11111LL11111111LL11LL00000000000110000011LLLLD1LLLL11
44444DDD000D00000D999666999999999999999C00080000000000000000000000000000000000000000000000000000000000000D01111111LLL1111111DLL00000000000011000001100001DLLLL1L
444444444440D000D099966696999999999999CC00000000000000000000000000000000000000000000000000000000000000000D01111111111LLLL11D1DL000000000000110000011000011D00L1L
DDDDDDD444444DDDD00999666669699999999CCC00000000000000000000000000000000000000000000000000000000000000000D111LL11111DD111L1D1DL000000000000110000011000011000010
DDDDDDDDD44444444409996F6666696666999CC000000000000000000000000000000000000000000000000000000000000000000D11L11L111D11D11DD1DL000000000000LL1000001L000D11000010
DDDD4D4D4DDD4444444499F96F6666666999CCC000000000000000000000000000000000000000000000000000000000000000000D11LDD1LLLDL1DDD11DDDD000DD00000001L00000L0000D1L000L10
DDDDDDDDDDDDDD4444444999F9F6F6FFF999CC00000000000CC00000000000000000000000000000000000000000000000000000DD11D11D1DDD1DL11D1DD04DDD4444440001000000100000D0000110
DDDD4D4D4D4D4D4D44444499999F9F99999CCC0000000999CC000000000000000000000000000000000000000000000000000000DDDDDDLLDD44D444D4D44D444444444444444444441000001D000110
DDDDDDDDDDDDDDDDDDD444444499999999CCC4D000DD999999990000000000000000000000000000000000000000000000044444444444D44D444DDD4DD4D44444444444444444444444444444000110
CDDDDDDD4D4D4D4D4D4D4444444444CCC4444D4D4D44D499999999DD0000000000000000000000000000004444444444444444444444444DD4444444444D444444444444444444444444444444444444
CCCDDDDDDDDDDDDDDDDDDDDD4444444444444444D4D44DDDDDD4DD44D44000000000444444444444444444444444444444444444444444444444444444444444D4D4D444444444444444444444444444
CCCCCDDDDDDDDD4D4D4D4D4D4D44444444D4D444444DDDD4444D44DD44444444444444444444444444444444444444444444444444444444444444444444444444444444444444D4D4D4D4D4D4444444
CCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDD4444444444444444444444444444444444444444444444444444444444444444444444444444DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD44444444444444444
CCCCCCCCCCDDDDDDDDDD4D4D4D4D4D4D4D4D444444D4D4D4D4D4D4D4D4444444444444D4D4D44444444444444444444D4D4D4D4DDDDDDDDDDDDDDDDDDD4D4D4D4D4D4D4D4D4D4DDDDDDDDDDDD4D4D444
CCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDD444444444444444444444444444444444444444DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD444
CCCCCCCCCCCCCCCDDDDDDDDDDDDDDD4D4D4D4D4D4D4D4D4D4DDDDDDDDDDDDDDDDDDDDDDDDDDD4D4D4D4D4D4D4D4D4D4D4DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
CCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
FCFCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDD4D4D4D4D4D4D4D4D4D4D4D4DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
FCFCFCFCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDD4D4D4D4D4D4D4D4D4D4D4DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
FCFCFCFCFCFCFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCF22222FCFCFCFCFCFCFCFC
CCCCCCCCCCCCCCCC2CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC222222222CCCCCCCCCCCCCC
CCFCFCFCFCFCFCF222FCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCFCFCFCFCFC22222222222CFCFCFCFCFCFC
CCCCCCCCCCCCCCC222CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC22222CC222221CCCCCCCCCCCC
CCCCCCCCFCFCFCF22222FCFCFCFCFCFCFCFCFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFC22222CFC12F221FCFCFCFCFCFC
CCCCCCCCCCCCCC222222CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC222222111CC221CCCCCCCCCCCC
CCCCCCCCCCCC22222C2CFCFCFCFCFCFCFCFCFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCFCCCCCCCCCCCFCFCFCFCFCFCFCFCFCFCFC2222222222F221FCFCCCCCCCCC
CCCCCCCCCCC22222CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC22222222222211CCCCCCCCCCCC
CCCCCCCCCC2222CCCCCCFCFCFCFCFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCFCFCFCFCFCFCFCFCFCFCFCFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCFCFCFCFCFC22222222211CCCCCCCCCCCCC
CCCCCCCCC2222CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC2C1C122111CCCCCCCCCCCCCC`;

const TITLE_SCREEN_ART = bitmap`
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000
0000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000010000000000000000000000000000000000000000
000000000000000000000000000000000000000LL00000000000000000000000000000000000012100000000000000000000000000000000000000000000000000000000000000000000100000000000
000000000000010000000000000000000000L000000000000000000000000000000000000001122211000000000000000000000000000010000000000000000000000000000000000000100000000000
0000000000001110000000000000000000LL2100000000000000000000000000000000000000012100000000000000000000000000000010000000000000000000000000000000000001210000000000
00000000000001000000000000000000LL001000000000000000L10000000000000000000000001000000000000000000000000000000121000000000000000000000000000000000112221100000000
0000000000000000000000000000000L000000000000000000000L0000000000000000000000001000000000000000000000000000011222110000000000000000000000000000000001210000000000
000000000000000000000100000000L00000000222222200000000L000000000000000000000000000000000000000000000000000000121000000000000000000000000000000000000100000000000
0000022200000000000000022000000000000222222222220000000L02220000000000000000000000000000000000000000000022222222000000000000022222200000000000222220100000000000
0022222220000000000000222220000000022222222222222200000022222200000100022222220000000222222002000022222222222222222222202222222222222222200222222222222200000000
0000222220000000000002222200L000002222222222222222200000L2222220000000002222000000002220222222000022200222222222200222200022222222000022200002222220222222000000
000002222000000000000222200L000002222212222222222222000000222222000000000220000000022000000222000222000022222220000022200022222200000002220002222200000222200000
000022222000000000002222200L000022222222211222221122200000222222000000000220000000222000000022000220000002222200000002220022220000000000220002222000000022200000
00002222220000000000222220L0000022211222111222211122200000222222200000000221000000222000000022000200000002222000000000220022222000000000020002222000000002220000
00002222220000000000222220L0000222111122212222111112220000222222220000000220000000022200000002000200000000222000000000220022222000020000000002222000000002220000
00002222220000000002202220000002211111122222221111L2220000220222222000000220000000022220000000000000000000222000000000020022220000220000000002222200000002220000
0000022022200000000220222L0000221111111222222211LLL2222000220000222200000222000000002222200000000000000000222000000000000022220002220000000000222200000022200000
0000022022200000000200220L000022111111122222221LL222222000020000022200000022000000000222200000000000000000222000000000000002222222220000000000222200000022200000
00000200002200000022002200000022111111122222222LL222221000020000002220000022000000000022220000000000000100220000000000000002222222220000000000222222202220000000
0000020000220000022000222000002221111122222222222222221000020000002220000022000000000002222000000000000000222000000000000002222202220000000000222222222200000000
000002000022200002200022200000222211L222222222222222211000022000000222000022000000000000022222000000000000222000000000000002220000220000000000222220222220000000
000002200002220002200022200000222222222222222222222221L000022000000222200022000000000000002222200000000000222000000000000002220000221000000000222200002220000000
000022200002220022200022220000222222222222222222211111L000022000000022220022000000000000000222200000000000222000000000000022220000020000000002222200002222000000
00002220000222002200002222000002222222221112222211111LL000222000000002222022000002000000000022200000000002222000000000000022220000000000000002222200000222000000
00002220000022222000002222000002222222211112222111111L0000222000000000222222000002000000000222000000000002222000000000000022220000000000002002222000000222200000
000022200000222220000222220000002222221111L222211111LL0000222000001000022220000002200000000222200000000002222000000000000022222000000000022002222000000022200000
0000222010002222000002222200000022222221LL222221111LL0000L222000000000022220000002222000002222000000000002222200000000000022222000000000022002222200000002220000
0000222010000220000002222200000002222222222211111LLL00000L222000000000002222000002222220022222000000000002222200000000000022222200000002220002222220000002222000
0000222121000200000002222220L0000022222222211111LLL0000000222000000000000222000002002222222220000000000022222200000000000022222220222222220002222222000000222200
002222222211L20000022222222200000002222111111LLLLL00000022222220000000000022000000000022222000000000000222222222100000002222222222222222200222222222220000222220
0LLLL22221LLLLL00000002222000L000000011111LLLLLL0000000L00220000000000000002000000000000000000000000000000022000000000000000022222222220000000022220000000002000
LLLLLLLL1LLLLLLL00000000000000L000000001LLLLLL00000000L0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000LL
LLLLLLLL1LLLLLLLL000000000000000000000000000000010000L000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000LLLL
LLLLLLLLLLLLLLLLLL000000000000000000000000000000100LL000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000LLLLLLLL
LLLL00000LLLLLLLLLL000000000000000000000000000002LL00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000LLLLLLLLLLL
LLL0000000LLLLLLLLLL000000000000000000000000000LL1000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000LLLLLLLLLLLLL1
LL00000000LLLLLLLLLL000000001000000000LLLL0000L121000000000000000000000000000000000000000000010000000000LLLLLLLL0000000000000000000000000000LLLLLLLLLLLLLLLLLLLL
LL000000000LLLLLLLLL000000012100000000000000011222110000000000000000000000000000000000000000121000000LLLLLLLLLLLLLLLLLLLLL000000000LLLLLLLLLLLLLLLLLLLLLLLLLLLLL
LLL00000000LLLLLLLLL000000001000000000000011222222222110000000000000000000000000000000000011222110000000LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
LLLLLLL0000LLLLLLLLL000000000000000000000000011222110000000000000000000000000000000000000000121000000000000LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
0LLLL000000LLLLLLLLL000000000000000000000000000121000000000000000000000000000000000000000000010000000000000000LLLLLLLLLLLLLLLLLLLLL1LLLLLLLLLLLLLLLLLLLLLLLLLLLL
00000000000LLLLLLLLL000000000000000000000000000121000000000000000000000000000000000000000000010000000000000000000LLLLLLLLLLLLLLLLL121LLLLLLLLLLLLLLLLLLLLLLLLLLL
00000000000LLLLLLLLL0000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000LLLLLLLLLLLLLL1LLLLLLLLLLLLLLLLLLLLLLLLLLLL
0000000000LLLLLLLLLL0000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL000
0000000000LLLLLLLLLL0000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000LLLLLLLLLLLLLLLLLLLLLLLL0000000010
000000000LLLLLLLLLLL00000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000LLLLLLLLLLL000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000LLLLLLLLLLLL000000000000000000000000000000000000000000000000000000000000000000000000000000000000022000000000022222222000000000022222000000000000002200000
00000LLL22222LLLLL00000000022000000000000000000220000000LLLLLLLLLLLLL1LLLLLLLLLLLLLLLLLLLL0010000000022222200000022222222222222220002222222200000000022222222000
0LLLLL22222222L1LL00000222222220000000100022222222LLLLLLLLLLLLLLLLLL121LLLLLLLLLLLLLLLLLL2222222LLLL222222220000022222111222222222009112211110000000222222222000
LLLLLL112222222LL000002222222220000000000222222222LLLLLLLLLLLLLLLLLLL1LLLLLLLLLLLLLLLLLLL22222222LLL222222220000022221111111111111009911199110000002221999999000
LLLLLL919112222L00000222222221100000000002222222222LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL22222222LLL22222222LLLLL11111999991999111009911199991000002119999999000
LLLLLL399911211100000112221111100000000002222199911LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL22222211LLL11112222LLLLL99911999999999999000991199999900091199999993000
LLLLLLL9999119991000111111199930000000LL11119999913LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL11119999LLL99111111LLLL999991999993399993000991999999999999119999993000
LLLLLLL39991999999999999911999300000LLLL39119999993LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL91199999LLL99991191LLLL999911999LLLLL399LLLL999999999999999119999990000
LLLLLLL39991999999999919991999000LLLLLLL391999999993LLLLLLLLLLLLLLLLLLLLLLLLLLLLD1LLLLLLL91199999LLL99999199LLLL399911993LLLLLL33LLLL999999999999999119999930000
LLLLLLL399999999999999999999990LLLLLLLL3999999999993LLLLLLLLLLL1DLLLLLLLLLLLLLLLDD1LLLLLL39199999LLL99999193LLLL3999999999933LLLLLLLL999999999999999199999993000
0000000399999999999999999999993LLLLLLLL999999LL99993LLLLLLLLLL1DDLLLLLLLLLLLLLL44DDLLLLLL39999999LL999999193LLLL39999999999993LLLLLLL399999999999999999999993000
0000000399999999999999999999993LLLLLLLL99999LLLL99993000000000044DLLLLLL22L22LL44DDLLLLLL3999999999999999993LLLL399999999999993LLLLLL39999999999999999999999300L
0000000399999999999999999999993LLLLLLL399999333399999000000000D44D0000002222200DDDDLLLLLL3999999999999999993LLLL399999999999993LL1LLL399999999999999999999993LLL
0000000399999999999999999999993LLLLLLL399999999999999300000000DDDD0000000220000D4DD0000003999999999999999993LLLL399999999999993LLLL00399999999999999999999993LLL
0000000399999999999999999999993LLLLL03999999999999999300000000DDD4400000002000D44DD0000003999999999999999993LLLL39999999993399300000039999999999999099999993LLLL
000000039999999999999L99999999LL0000039999999999999999300000000D444D00000D1D00D44DD0000003999999999999999993000039999999930003000000039999999999999099999993LLLL
LLLLLLL39999999999999L99999999000000099999999999999999330000000D444D00000DDDDDDDDDD000D403999999999999999993000039999999930000000000039999991399330L999999933LLL
LLLLLLL3999999L99999LL99999999300000099999999999999999930000000D44DD000DDDDDDDDDDD000C44D399999999999999999300003999999999930000000003999999033333LL999999933LLL
LLLLLLL3999999L99999LL99999993300000399999999009999999933000000DDDDDDDDD4444DDD4DDDDCD0D439999993330399999930000399999999999999333003399999900333LLL999999993LLL
LLLLLL33999999LL99900099999993300000399999999009999999993000000DDDDDDDD44444444444DDDD000399999300003999999300003399999999999999930033999999LL333LLL999999993LLL
LLLLLL33999999LL99900099999993300000399999990000999999999300000DDD44444444444444444DDD000339999300003999999930003399999999999999930033999999LL1LLLLL399999993LLL
LLLLLL33399999LLLLLLLL9999999333LLL0339999930000339999993300000DDDD444444444444444DDD0000339999300003999999930003339999999999999930033399993LL1LLLLL339999333LLL
LLLLLL33399993LLLLLLLL3999993333LLLL339993300000033999933330000DDDDD4444444444444DDDDLLLL33999930000399999993000333333999999999993LLL3333933L121LLLL333393333LLL
LLLLLLL3333393LLLLLLLL3999333333LLLL3333333LLLLL0033333333000000DDDD444444444444DDDDLLLLL3339993LLLL399999993LL0333333333999999933LLL3333333122211LLL3333333LLLL
LLLLLLL3333333LLLLLLLLL3333333LLLLLLL3333LLLLLLLLLL333333300000000DDDDDD4444DDDDD0LLLLLLL3339993LLLL333999993LLLL33333333399993333LLL3333333L121LLLLL333333LLLLL
LLLLLLL3333333LLLLLLLLL333333LLLLLLLL333LLLLLLLLLLL3333330000000000DDDDDDDDDDDDD0000LLLLL3333993LLLL333399933LLLLL3333L3333933333LLLLL33333LLL1LLLLLL33333LLLLLL
LLLLLLLL33333LLLLLLLLLL33333LLLLLLLLL333LLLLLLLLLLLL3333LLL00000020DDDDDDDDDDDDD0000000LL3333933LLLLLLL33333LLLLLLL33LLL3333333LLLLLLL33LLLLLL1LLLLLL3333LLLLLLL
LLLLLLLL33LLLLLLL00000033330000LLLLLL333LLLLLLLLLLLL333LLLLLL000112DDDDDDDDDDDDD1100000000333333LLLLLLL3333LLLLLLLL33LLL33333LLLLLLLLLL3LLLLLLLLLLLLLL333LLLLLLL
LLLLL10003000000000000003330030000000333LLLLLLL1LLL333LLLLLLLLLL111222DDDDDDD2111100000000003333LLLLLLLL333LLLLLLLL33LLL3333LLLLLLLLLLL33LLLLLLLLLLLLL333LLLLLLL
0000000003300000000000003330000000000333000000121LLL33LLLLLLLLLLL111112222222111110000000000033LLLLLLLLL333LLLLLLLL33LLL333LLLLLLLLLLLL33LLLL00LLLLLLLL3LLLLLLLL
000000000330000000000000030000000000003000000001000L33LLLLLLLLLLL111111111111111100000000000003000LLLLLLL33LLLLLLLL33LLL333LLLLLLLLLLLL3LLLL00LLLLLLLLL3LLL00000
00000000030000000000000003000000000000300000000000033300LLLLLLLLL11111111111111C10000000000000300000LLLLL33LLLLLLLL33LLL33LLLLLLLLLLLLL3LLLL00LLLLLLLL0300000000
00000000030000000000000003000000000000300000000000033300000000LLLLCCCCCCCCC11CCC00000000001000300000000LL33LLLLLLLLLLLLL3LLLLLLLLLLLLLLLLLLLLLLLLL00000300000000
000000000000000000000000030000000000003000000000000333000000000000DCCCCCCDCCCCCCLLL000000000003000000000030LLLLLLLLLLLLL33LLLLLLLLLLLLLLLLLL00000000000300000000
000000000000000000000000031000000000003000000000000033000000000000DDCCCCCD4CCCDC000LLLL00000003000000000030100000LLLLLLL33LLLLLLLLLLLL00000000000000000300000000
000000000000000000000000000000000000003000000000000033000000000000DDCCCCCD4DCCDC0000000LL00000000000000003010000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000030000000000000DDDCCCCDD4CCD000000000000000000000000003121000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000030000000000000DCDDCCCCD4CCD000000000000000000000000013222110000000000000000000000000000000000000000000000000
000000000000000444444444444444444444444444400000000030000000000000DCCDCCCCD4CCD000000000000000000000000003121000000000000000000000000000000000000000000000000004
000000000044444444444444444444444444444444444444440000000000000000CCCDCCCCCDCCC000000000000000000000000000010000000000000000000000000000000000000000000000444444
000000044444444444444444444444444444444444444444444444440000000000CCCDCCCCCCCCC000000000000000000000000000010000000000000000000000000000000000000000004444444444
0044444444444444DDDDDDDDDDDDDDDDDDDDD44444444444444444444444440000CCCCCCCCCCCCC000000000000000000000000000000000000000000000000000000000000000000444444444444444
444444444D4D4D4D4D4D4D4D4D4D4D4D4D4D4D4D4D4D4D444444444444444444444444CCCCCCCCC000000000000000000000000000000000000000000000000000000000000444444444444444444444
44444DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD444444444444444444444CC4444444000000000000000000000000000000000000000000000000044444444444444444444444444444
44DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD4D4D4D4D4D4D4D444444444444444444444444444444444444444444444444400000000000444444444444444444444444444444444444444DDD
DDDDDDDDCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD44444444444444444444444444444444444444444444444444444444444444444444444444444444444DDDDDDDDDDD
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDD4D4D4D4D4D4D4D4D4D4D4D4D444444444444444444444444444444444444444D4D4D4D444444444444444444DDDDDDDDCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD444444444444444DDDDDDDDDCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDD4D4D4D4D4D4D4D4D4D4D4D4D4D4D4DDDDD4D4D4D4DDDDDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCC222CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCC22222CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCC22222CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC22CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCFCFCFCFCFCFCFCFCFCFCCCCCCCCCCCCCCC
CCCCCCCCCCC222222CCCCCCCCCCCCCCCCCCCCCCCCCCCCC22222CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC22222CCCCCCCCCCCCCCCCCCCCC2CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC88CCCCCCCCCC
CCFCFCFCFCF22222211CFCFCFCFCFCFCFCFCFCFCCCCCC2222222CCCCCCCCCC22CCCCCCCCCCCCCCCCCCCCC2222222CCCCCCCC2222FCFCFC2222FCFCFCFCFCFCCCCC2222CCFCFCFCFCFCF8888CFCFCFCFC
CCCCCCCCCCC222222211CCCCCCCCCCCCCCCCCCCCCCCC222222222222CCCCC2222CCCCCCCCCCCCCCCCCCC222222222CCCCCC222222CCC1122211CCCCCCCCCCCCC22222222CCCCCCCCCCC8888HCCCCCCCC
FCFCFCFCFC2222222211FCFCFCFCFCFCFCFCFCFCFCFC2222222222222CFCF22222FCFCFCFCFCFCFCFCCC2222222222FCFC2222222211222221CCCCCCCCCCCCC2212222222CCCCCCCCCC888H88CCCCCCC
CCCCCCCCC2222222211CCCCCCCCCCCCCCCCCCCCCCCC222222CCC222222CC2222222CCCCCCCCCCCCCCCCC2222222222CCCC2222222222222221CCCCCCCCCCCC2222122CC222CCCCCCCCCCHH8888H8888C
FCCCCCC22222111C11CCCCCCCCCCCCCCCCCCCCFCFCF22222FCC1222221FC2222222CFCFCFCFCFCFCFCCC22222222221CCCC222222222222221FCFCFCFCFCFC2222212CFC222CFCFCFCFC888888H8888H
CCCCC222222111CCCCCCCCCCCCCCCCCCCCCCCCCCCCC22222CC12222221CC22222222CCCCCCCCCCCCCC22222CCC22221CCCCC2222222222221CCCCCCCCCCCC222222222C122CCCCCCCCCCC8888H88888H
FCCC22222211CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC22222222222211CC22222222CCCCCCCCCCCCC22222CCCCC2221CCCCCCCCC222222221CFCFCFCFCFCF2222222122222FCFCFCFCFCFC88H88888H8
C2222222111CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC6262626262621CCC62626262CCCCCCCCCCCC626262CCCC12621CCCCCCCCC626262611CCCCCCCCCCCC222222211222CCCCCCCCCCCCCCCCCC888H8
222222211CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC2222222222211CFC22222222CCCC2CCCCCCC222222C11C12221CFCFCFCCCC2222221FCFCFCCCCCCCC2222222212222CCCCCCFCFCFCFCFCFCFH88
2222222CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC626262626211CCCCC2626262111262CCCCC2626262626162611CCCCCCCCCC2626261CCCCCCCCCCCCCC2222222221212CCCCCCCCCCCCCCCCCCCC8
2222222CFCFCFCFCFCFCFCFCFCF6FCCCCCCCCCCCCCCC26262626CCCCCCFCCC2626262626262CFCF62626262626262CCCFCFCFCFCC626261CCCCCCCCCFCFCFC22222222211212CCCCCCCCCCCCCCCCCCCC
C2222221CCCCCCCCCCCCCC6CCC6CCCCCCCCCCCCCCCCCC2626262CCCCCCCCCC6262626262626CCCC2626262626262CCCCCCCCCCCC6262621CCCCCCCCCCCCCCCC22222222221222CCCCCCCCCCCCCCCCCCC
FC222221FCFCFCFCFC6CF69999999CFCFCFCFCCCCCCCCC262626CCCCCCCCCC26262626262626FCF6262626262626CCFCFCFCFCCC26262CCCFCFCFCFCFCFCCCCC22222222222211FCFCFCFCFCFCFCFCFC
C2222211CCCCCCCCCC6C9999999999966CCCCCCCCCCCCC666666FCCCCCCCC66666666666666FCCC6666666666666CCCCCCCCCCCC66666CCCCCCCCCCCCCCCCCCCC22CC22222111CCCCCCCCCCCCCCCCCCC
CC11111CCCCCCCCCCC69999999999999FCFCFCFCFCCCCC262626FCCCCCCCC6262626262626FFFCFC262626262626FCCCCCCCCCCC26262CCCCCCCCCCCCCCCCCCCCCCCFC111111FCFCCCCCCCCCCCCCCCCC
CCC111CCCCCCCCCC6C999999996999999CCCCCCCCCCCCC6666FFFCCCCCCCCCFF66666666FFFFFCCC66FFFFC66666FCCCCCCCCCCCC666FFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCC6CC69999999C6C999999CC6CCFCFCFCC6666FFCCCCCCCCCCCCFFFFFFFFFFCCCCCCCFFCFFCCC66FFFCCCCCCCCCCCCFFFFCCCCCCCCCCCCCFCFCFCFCFCFCFCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCC6C99999966C6CC6999966CCCCCCCCCC6FFFFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCFFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCC6C999999996CCCCCCC6999999CCCCCCCCCFFFFFCFCFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCFCFCFCFCFCFCFCFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCC999999999C6CCCCCCCCC99999CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC`;

const PLAY_BUTTON_FRAMES = bitmap`
4D4D4D4D4D4D4D444444444444444444444444CCCCCCCCC0000000000000000000000000000000000000000000000000
DDDDDDDDDDDDDDDDDDDD444444444444444444444CC44444440000000000000000000000000000000000000000000000
DDDDDDDDDDDD4D4D4D4D4D4D4D4444444444444444444444444444444444444444444444444000000000004444444444
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD44444444444444444444444444444444444444444444444444444444444444
CCCCCCCCCCDDDDDDDDDDDDDD4D4D4D4D4D4D4D4D4D4D4D4D444444444444444444444444444444444444444D4D4D4D44
CCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD4444444444
CCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDD4D4D4D4D4D4D4D4D4D4D4D4D4D4D4DDDDD4D4D4D4DDDDDDDDDDD
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC22CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCFC
CCCCCCCCCCCCCC22222CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC22222CCCCCCCCCCCCCCCCCCCCC2CCCCCCCCCCCCCCC
FCFCFCFCCCCCC2222222CCCCCCCCCC22CCCCCCCCCCCCCCCCCCCCC2222222CCCCCCCC2222FCFCFC2222FCFCFCFCFCFCCC
CCCCCCCCCCCC222222222222CCCCC2222CCCCCCCCCCCCCCCCCCC222222222CCCCCC222222CCC1122211CCCCCCCCCCCCC
FCFCFCFCFCFC2222222222222CFCF22222FCFCFCFCFCFCFCFCCC2222222222FCFC2222222211222221CCCCCCCCCCCCC2
CCCCCCCCCCC222222CCC222222CC2222222CCCCCCCCCCCCCCCCC2222222222CCCC2222222222222221CCCCCCCCCCCC22
CCCCCCFCFCF22222FCC1222221FC2222222CFCFCFCFCFCFCFCCC22222222221CCCC222222222222221FCFCFCFCFCFC22
CCCCCCCCCCC22222CC12222221CC22222222CCCCCCCCCCCCCC22222CCC22221CCCCC2222222222221CCCCCCCCCCCC222
CCCCCCCCCCCC22222222222211CC22222222CCCCCCCCCCCCC22222CCCCC2221CCCCCCCCC222222221CFCFCFCFCFCF222
CCCCCCCCCCCC2222222222221CCC22222222CCCCCCCCCCCC222222CCCC12221CCCCCCCCC222222211CCCCCCCCCCCC222
CCCCCCCCCCCC2222222222211CFC22222222CCCC2CCCCCCC222222C11C12221CFCFCFCCCC2222221FCFCFCCCCCCCC222
CCCCCCCCCCCC222222222211CCCCC2222222111222CCCCC2222222222122211CCCCCCCCCC2222221CCCCCCCCCCCCCC22
CCCCCCCCCCCC62626262CCCCCCFCCC6262626262626CFCF26262626262626CCCFCFCFCFCC262621CCCCCCCCCFCFCFC22
CCCCCCCCCCCCC2222222CCCCCCCCCC2222222222222CCCC2222222222222CCCCCCCCCCCC2222221CCCCCCCCCCCCCCCC2
FCFCFCCCCCCCCC626262CCCCCCCCCC62626262626262FCF2626262626262CCFCFCFCFCCC62626CCCFCFCFCFCFCFCCCCC
6CCCCCCCCCCCCC2626261CCCCCCCC62626262626262FCCC6262626262626CCCCCCCCCCCC26262CCCCCCCCCCCCCCCCCCC
FCFCFCFCFCCCCC6262621CCCCCCCC2626262626262F1FCFC626262626262FCCCCCCCCCCC62626CCCCCCCCCCCCCCCCCCC
9CCCCCCCCCCCCC2626F1FCCCCCCCCC1F262626261F1F1CCC261F1FC626261CCCCCCCCCCCC6261FCCCCCCCCCCCCCCCCCC
9CC6CCFCFCFCC6666FFCCCCCCCCCCCCFFFFFFFFFFCCCCCCCFFCFFCCC66FFFCCCCCCCCCCCCFFFFCCCCCCCCCCCCCFCFCFC
966CCCCCCCCCC6FFFFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCFFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
999CCCCCCCCCFFFFFCFCFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCFCFCFCFCFCFCFCFCCCCCCCCCCCCCCCCC
9999CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

4D4D4D4D4D4D4D444444444444444444444444CCCCCCCCC0000000000000000000000000000000000000000000000000
DDDDDDDDDDDDDDDDDDDD444444444444444444444CC44444440000000000000000000000000000000000000000000000
DDDDDDDDDDDD4D4D4D4D4D4D4D4444444444444444444444444444444444444444444444444000000000004444444444
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD44444444444444444444444444444444444444444444444444444444444444
CCCCCCCCCCDDDDDDDDDDDDDD4D4D4D4D4D4D4D4D4D4D4D4D444444444444444444444444444444444444444D4D4D4D44
CCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD4444444444
CCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDD4D4D4D4D4D4D4D4D4D4D4D4D4D4D4DDDDD4D4D4D4DDDDDDDDDDD
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDCCCCCCCCC
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
CCCCCCCCCCCCCCCC22CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCFC
CCCCCCCCCCCCCC22222CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC22222CCCCCCCCCCCCCCCCCCCCC2CCCCCCCCCCCCCCC
FCFCFCFCCCCCC2222222CCCCCCCCCC22CCCCCCCCCCCCCCCCCCCCC2222222CCCCCCCC2222FCFCFC2222FCFCFCFCFCFCCC
CCCCCCCCCCCC222222222222CCCCC2222CCCCCCCCCCCCCCCCCCC222222222CCCCCC222222CCC1122211CCCCCCCCCCCCC
FCFCFCFCFCFC2222222222222CFCF22222FCFCFCFCFCFCFCFCCC2222222222FCFC2222222211222221CCCCCCCCCCCCC2
CCCCCCCCCCC222222CCC222222CC2222222CCCCCCCCCCCCCCCCC2222222222CCCC2222222222222221CCCCCCCCCCCC22
CCCCCCFCFCF22222FCC1222221FC2222222CFCFCFCFCFCFCFCCC22222222221CCCC222222222222221FCFCFCFCFCFC22
CCCCCCCCCCC22222CC12222221CC22222222CCCCCCCCCCCCCC22222CCC22221CCCCC2222222222221CCCCCCCCCCCC222
CCCCCCCCCCCC22222222222211CC22222222CCCCCCCCCCCCC22222CCCCC2221CCCCCCCCC222222221CFCFCFCFCFCF222
CCCCCCCCCCCC6262626262621CCC62626262CCCCCCCCCCCC626262CCCC12621CCCCCCCCC626262611CCCCCCCCCCCC222
CCCCCCCCCCCC2222222222211CFC22222222CCCC2CCCCCCC222222C11C12221CFCFCFCCCC2222221FCFCFCCCCCCCC222
CCCCCCCCCCCC626262626211CCCCC2626262111262CCCCC2626262626162611CCCCCCCCCC2626261CCCCCCCCCCCCCC22
CCCCCCCCCCCC26262626CCCCCCFCCC2626262626262CFCF62626262626262CCCFCFCFCFCC626261CCCCCCCCCFCFCFC22
CCCCCCCCCCCCC2626262CCCCCCCCCC6262626262626CCCC2626262626262CCCCCCCCCCCC6262621CCCCCCCCCCCCCCCC2
FCFCFCCCCCCCCC262626CCCCCCCCCC26262626262626FCF6262626262626CCFCFCFCFCCC26262CCCFCFCFCFCFCFCCCCC
6CCCCCCCCCCCCC666666FCCCCCCCC66666666666666FCCC6666666666666CCCCCCCCCCCC66666CCCCCCCCCCCCCCCCCCC
FCFCFCFCFCCCCC262626FCCCCCCCC6262626262626FFFCFC262626262626FCCCCCCCCCCC26262CCCCCCCCCCCCCCCCCCC
9CCCCCCCCCCCCC6666FFFCCCCCCCCCFF66666666FFFFFCCC66FFFFC66666FCCCCCCCCCCCC666FFCCCCCCCCCCCCCCCCCC
9CC6CCFCFCFCC6666FFCCCCCCCCCCCCFFFFFFFFFFCCCCCCCFFCFFCCC66FFFCCCCCCCCCCCCFFFFCCCCCCCCCCCCCFCFCFC
966CCCCCCCCCC6FFFFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCFFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
999CCCCCCCCCFFFFFCFCFCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCFCFCFCFCFCFCFCFCCCCCCCCCCCCCCCCC
9999CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC`
	.split("\n\n");

let currentLegendChar = 400; // start after the other function ends
function getLegendChar2() {
	const char = String.fromCharCode(currentLegendChar++);
	if (char == "." || char == "\n" || char == " ") {
		// skip reserved characters
		return String.fromCharCode(currentLegendChar++);
	}
	return char;
}

function generateScreen(SCREEN_ART) {
	const splitArt = splitBitmap(SCREEN_ART);
	const legend = splitArt.map(chunk => [
		getLegendChar2(),
		chunk,
	]);

	// create the map by joining every char for the image into one string, then inserting newlines
	const map = legend
		.map((v) => v[0])
		.join("")
		.replace(/(.{10})/g, "$1\n")
		.slice(0, -1);

	return [legend, map];
}

const [gameOverLegend, gameOverMap] = generateScreen(GAME_OVER_ART);
const [titleScreenLegend, titleScreenMap] = generateScreen(TITLE_SCREEN_ART);

const [playButtonChunks1, playButtonChunks2] = PLAY_BUTTON_FRAMES.map(splitBitmap);
// get the list of legend characters that the play button stuff should use
const playButtonCoordinates = [[2, 6], [3, 6], [4, 6], [5, 6], [6, 6], [7, 6], [2, 7], [3, 7], [4, 7], [5, 7], [6, 7], [7, 7]];
const titleScreenMapSplit = titleScreenMap.split("\n");
const playButtonChars = playButtonCoordinates.map(coords => titleScreenMapSplit[coords[1]][coords[0]]);

function splitBitmap(bitmap) {
	const rows = bitmap.trim().split("\n");
	const chunks = [];
	const chunkRows = rows.length / 16;
	const chunkCols = rows[0].length / 16;

	for (let i = 0; i < chunkRows; i++) {
		for (let j = 0; j < chunkCols; j++) {
			let chunk = [];
			for (let r = 0; r < 16; r++) {
				const rowIndex = i * 16 + r;
				const startCol = j * 16;
				const endCol = startCol + 16;

				chunk.push(rows[rowIndex].slice(startCol, endCol));
			}
			chunks.push(chunk.join("\n"));
		}
	}

	return chunks;
}

// get a unique number given an x and y, using cantor's pairing function
function getPositionHash(x, y) {
	return ((x+y) * (x+y+1) * 0.5) + y; // cantor's pairing function
}

// get a unique character for each position
function getLegendChar(x, y) {
	x++;
	y++;
	return String.fromCharCode(getPositionHash(x, y) + 128); // add 128 so it's past all the normal chars we might want to use;
}

const STARTING_LEGEND=[];
const CUSTOM_LEGEND_CHARS = [];
for (let y = 0; y < 5; y++) {
	let row = [];
	for (let x = 0; x < 6; x++) {
		const ch = getLegendChar(x, y);
		row.push(ch);
		STARTING_LEGEND.push([ch, EMPTY_BITMAP]);
	}
	CUSTOM_LEGEND_CHARS.push(row);
}

const HOLES = [
	{x: 2, y: 1, type: -1, bonking: false, missedBonk: false, popupTime: -1},
	{x: 3, y: 1, type: -1, bonking: false, missedBonk: false, popupTime: -1},
	{x: 1, y: 2, type: -1, bonking: false, missedBonk: false, popupTime: -1},
	{x: 2, y: 2, type: -1, bonking: false, missedBonk: false, popupTime: -1},
	{x: 3, y: 2, type: -1, bonking: false, missedBonk: false, popupTime: -1},
	{x: 4, y: 2, type: -1, bonking: false, missedBonk: false, popupTime: -1},
	{x: 2, y: 3, type: -1, bonking: false, missedBonk: false, popupTime: -1},
	{x: 3, y: 3, type: -1, bonking: false, missedBonk: false, popupTime: -1},
]

const CURRENT_ANIMATIONS_LEGEND = [];

const CAT_ANIMATION_RARITY = 0.2;
function updateCat() {
	let ground10_bitmap;
	const rand = Math.random();
	if (rand < CAT_ANIMATION_RARITY) {
		ground10_bitmap = GROUND10_FRAME_2;
	} else if (rand < CAT_ANIMATION_RARITY * 2) {
		ground10_bitmap = GROUND10_FRAME_3;
	} else {
		ground10_bitmap = GROUND10_FRAME_1;
	}
	setLegend([GROUND10, ground10_bitmap]);
}

function updateAnimations() {
	setLegend(...CURRENT_ANIMATIONS_LEGEND, ...CORE_LEGEND);
}

function popup(holeIndex, typeIndex) {
	const hole = HOLES[holeIndex];
	x = hole.x;
	y = hole.y;
	hole.type = typeIndex;
	hole.popupTime = Date.now();

	const LEGEND_ARRAY = [getLegendChar(x, y), MONSTERS[typeIndex][0]];
	CURRENT_ANIMATIONS_LEGEND.push(LEGEND_ARRAY);

	setTimeout(() => {
		if (!hole.bonking) {
			LEGEND_ARRAY[1] = MONSTERS[typeIndex][1];
			updateAnimations();
		}
	}, 50);
	setTimeout(() => {
		if (!hole.bonking) {
			LEGEND_ARRAY[1] = MONSTERS[typeIndex][2];
			updateAnimations();
		}
	}, 100);
  	setTimeout(() => {
		if (!hole.bonking) {
			LEGEND_ARRAY[1] = MONSTERS[typeIndex][3];
			updateAnimations();
			// remove the animation from the animation legend, it will stop re-rendering
			CURRENT_ANIMATIONS_LEGEND.splice(CURRENT_ANIMATIONS_LEGEND.indexOf(LEGEND_ARRAY), 1);
		}
	}, 200);
}

function bonk(holeIndex) {
	const hole = HOLES[holeIndex];
	
	if (hole.bonking || hole.missedBonk) {
		return
	}

	const current = Date.now();
	if (current - lastBonk < 250) return;
	lastBonk = current;
	
	const x = hole.x;
	const y = hole.y;
	
	// if they mis-bonk an empty hole
	if (hole.type == -1) {
		hole.missedBonk = true;

		playTune(BONK_MELODY_MISS);

		// increase the cooldown
		lastBonk = current + 250;

		const LEGEND_ARRAY = [getLegendChar(x, y), HAMMER];
		CURRENT_ANIMATIONS_LEGEND.unshift(LEGEND_ARRAY);
		updateAnimations();

		setTimeout(() => {
			LEGEND_ARRAY[1] = HAMMER_DOWN;
			updateAnimations();
		}, 50)

		setTimeout(() => {
			LEGEND_ARRAY[1] = HAMMER;
			updateAnimations();
		}, 100)

		setTimeout(() => {
			hole.missedBonk = false;

			LEGEND_ARRAY[1] = EMPTY_BITMAP;
			updateAnimations();

			CURRENT_ANIMATIONS_LEGEND.splice(CURRENT_ANIMATIONS_LEGEND.indexOf(LEGEND_ARRAY), 1);
		}, 500)
		return;
	}

	playTune(BONK_MELODY_HIT);
	
	hole.bonking = true;
	score += Math.max(100, 1000 - (Date.now() - hole.popupTime));
	drawStats();
	
	const LEGEND_ARRAY = [getLegendChar(x, y), MONSTERS[hole.type][4]];
	CURRENT_ANIMATIONS_LEGEND.push(LEGEND_ARRAY);
	updateAnimations();

	setTimeout(() => {
		LEGEND_ARRAY[1] = MONSTERS[hole.type][5];
		updateAnimations();
	}, 50);
  	setTimeout(() => {
		LEGEND_ARRAY[1] = MONSTERS[hole.type][6];
		updateAnimations();
	}, 100);
    setTimeout(() => {
		LEGEND_ARRAY[1] = MONSTERS[hole.type][7];
		updateAnimations();
	}, 125);
	setTimeout(() => {
		LEGEND_ARRAY[1] = HAMMER;
		updateAnimations();
	}, 150);
	setTimeout(() => {
		LEGEND_ARRAY[1] = EMPTY_BITMAP;
		updateAnimations();
		CURRENT_ANIMATIONS_LEGEND.splice(CURRENT_ANIMATIONS_LEGEND.indexOf(LEGEND_ARRAY), 1);
		hole.bonking = false;
		hole.type = -1;
	}, 750);
}


function mole() {
	if (!gameRunning) return;

	let holeIndex = -1;
	let attempts = 0;
	// repeat until we get an unused hole
	while (holeIndex < 0 || HOLES[holeIndex].type != -1) {
		holeIndex = Math.floor(Math.random() * 8);
		if (++attempts > 36) {
			console.log("Holes are full!");
			return;
		}
	}

	popup(holeIndex, Math.floor(Math.random() * MONSTERS.length));
  
	// adjust the current timer and start time to hit the max speed before 'double time' starts
	const adjustedStartTime = START_TIME - DOUBLE_TIME
	const adjustedTimer = Math.max(timer - DOUBLE_TIME, DOUBLE_TIME);
	const timeout = START_INTERVAL - (START_INTERVAL - END_INTERVAL) * ((adjustedStartTime - adjustedTimer)/ adjustedStartTime)
	setTimeout(mole, timeout);
}

function drawStats() {
	updateCat();
	
	clearText();

	// controls
	if (START_TIME - timer <= 15) {
		addText("W", {x: 3, y: 3, color: HOLES[0].type == -1 ? color`3` : color`2`});
		addText("A", {x: 2, y: 4, color: HOLES[2].type == -1 ? color`3` : color`2`});
		addText("S", {x: 3, y: 5, color: HOLES[6].type == -1 ? color`3` : color`2`});
		addText("D", {x: 4, y: 4, color: HOLES[4].type == -1 ? color`3` : color`2`});

		addText("I", {x: 16, y: 3, color: HOLES[1].type == -1 ? color`7` : color`2`});
		addText("J", {x: 15, y: 4, color: HOLES[3].type == -1 ? color`7` : color`2`});
		addText("K", {x: 16, y: 5, color: HOLES[7].type == -1 ? color`7` : color`2`});
		addText("L", {x: 17, y: 4, color: HOLES[5].type == -1 ? color`7` : color`2`});
	}

	if (START_TIME - timer <= 5) {
		addText("Whack the monsters!", {x: 1, y: 0, color: color`6`})
	}

	if (!gameOver) {
		addText(timer.toString(), { x: 9, y: 1, color: color`2` });
	}
	
	let scoreX = 6;
	if (score >= 100) {
		scoreX = 5;
	}
	addText("Score: " + score.toString(), {x: scoreX, y: 14, color: color`2` });
}
	

// looks weird bc the ground is varied
const MAIN_MAP = map`
163181
43RB49
2RBRB2
05RB47
124324`;

// stuff for the background that goes behind the text
const OVERLAY_LEGEND = [
	[getLegendChar(2, 0), OVERLAYS[0]], // left (behind timer)
	[getLegendChar(3, 0), OVERLAYS[1]], // right (behind timer)
	[getLegendChar(1, 4), OVERLAYS[2]], // left (behind score)
	[getLegendChar(2, 4), OVERLAYS[4]], // center (behind score)
	[getLegendChar(3, 4), OVERLAYS[4]], // center (behind score)
	[getLegendChar(4, 4), OVERLAYS[3]], // right (behind score)
];

// TODO: title screen
var gameRunning = false;
var gameOver = false;
const START_TIME = 60;
const START_INTERVAL = 3000; // starting time between moles
const END_INTERVAL = 500; // ending time between moles
const DOUBLE_TIME = 15 // when the timer hits this number, 2 moles appear at once
var timer;
var score = 0;
var lastBonk;
let musicPlayback;

function startGame() {
	console.log("%cStarting Game", "color: blue; font-size:16px")
	timer = START_TIME;
	score = 0;
	gameRunning = true;
	gameOver = false;

	titlePlayback.end();
	musicPlayback = playTune(MUSIC_GAMEPLAY, Infinity)

	clearInterval(titleAnimationInterval);
	
	// the way this works is, it sets a map where each tile has a different sprite. then, those can be controlled indiviudally by setting the legend.
	// it sets the map afterward by adding sprites 1 by 1. This way, the top layer of sprites can be controlled individually
	// this is basically all just a workaround for the fact that adding a new sprite adds it at the bottom of the z-order stack
	setLegend(...CORE_LEGEND, ...STARTING_LEGEND, ...OVERLAY_LEGEND);
	setMap(MAIN_MAP);
	for (let x = 0; x < 6; x++) {
		for (let y = 0; y < 5; y++) {
			addSprite(x, y, CUSTOM_LEGEND_CHARS[y][x]);
		}
	}

	drawStats();
	const timerInterval = setInterval(() => {
		timer--;
		if (timer == 0) {
			clearInterval(timerInterval)
			endGame();	
		};

		clearText();
		drawStats();
	}, 1000)

	mole();
	// when the timer hits DOUBLE_TIME, 2 moles appear at once
	setTimeout(mole, (timer - DOUBLE_TIME) * 1000)
}

function endGame() {
	gameRunning = false;
	gameOver = true;
	setTimeout(() => {gameOver = false}, 4000);

	musicPlayback.end();
	playTune(GAME_OVER_MELODY1);
	setTimeout(() => playTune(GAME_OVER_MELODY2), 2000);
	setTimeout(() => titlePlayback = playTune(MUSIC_TITLE, Infinity), 3000);

	setLegend(...gameOverLegend);
    setMap(gameOverMap);

    clearText();
	let scoreX = 6;
	if (score >= 100) {
		scoreX = 5;
	}
	addText("Score: " + score.toString(), {x: scoreX, y: 10, color: color`2` });
}


// title music
var titlePlayback = playTune(MUSIC_TITLE, Infinity);

setLegend(...titleScreenLegend);
setMap(titleScreenMap);

let titleAnimationState = 0;
const titleAnimationInterval = setInterval(() => {
	if (titleAnimationState == 0) {
		chunksList = playButtonChunks1;
	} else {
		chunksList = playButtonChunks2;
	}
	setLegend(...playButtonChars.map((ch, index) => [ch, chunksList[index]]));
	
	titleAnimationState = !titleAnimationState;
}, 750)


onInput("w", () => { if (gameRunning) {bonk(0)} else if (!gameOver) {startGame()} });
onInput("a", () => { if (gameRunning) {bonk(2)} else if (!gameOver) {startGame()} });
onInput("s", () => { if (gameRunning) {bonk(6)} else if (!gameOver) {startGame()} });
onInput("d", () => { if (gameRunning) {bonk(4)} else if (!gameOver) {startGame()} });
onInput("i", () => { if (gameRunning) {bonk(1)} else if (!gameOver) {startGame()} });
onInput("j", () => { if (gameRunning) {bonk(3)} else if (!gameOver) {startGame()} });
onInput("k", () => { if (gameRunning) {bonk(7)} else if (!gameOver) {startGame()} });
onInput("l", () => { if (gameRunning) {bonk(5)} else if (!gameOver) {startGame()} });
